package com.atos.optical.controller;

import com.atos.optical.common.ApiResult;
import com.atos.optical.common.BaseHttpController;
import com.atos.optical.model.bo.TreeNodeBo;
import com.atos.optical.model.po.SysMenuInfo;
import com.atos.optical.service.SysMenuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wanghra
 * @version 1.0
 * @description
 * @date 2025/8/13
 */
@RestController
@RequestMapping("/menu/info")
public class SysMenuInfoController extends BaseHttpController {
    @Autowired
    private SysMenuInfoService service;
    
    @PostMapping("/save")
    public ApiResult<Boolean> save(@RequestBody SysMenuInfo entity) {
        return new ApiResult<>(service.save(entity));
    }
    
    @PostMapping("/update")
    public ApiResult<Boolean> update(@RequestBody SysMenuInfo entity) {
        return new ApiResult<>(service.updateById(entity));
    }
    
    @DeleteMapping("/delete/{id}")
    public ApiResult<Boolean> delete(@PathVariable("id") String id) {
        return new ApiResult<>(service.removeById(id));
    }
    
    @GetMapping("/getById/{id}")
    public ApiResult<SysMenuInfo> getById(@PathVariable("id") String id) {
        return new ApiResult<>(service.getById(id));
    }
    
    @GetMapping("/getAllTree")
    public ApiResult<List<TreeNodeBo>> getAllTree() {
        return new ApiResult<>(service.getAllTree());
    }
    
    @GetMapping("/getUserMenuTree/{userId}")
    public ApiResult<List<TreeNodeBo>> getUserMenuTree(@PathVariable("userId") String userId) {
        return new ApiResult<>(service.getUserMenuTree(userId));
    }
}
